<!DOCTYPE HTML>
<html>
  <head>
	<?php echo Yaf_View_Simple::render("header.phtml"); ?>
  </head>
  <body>
	<?php echo Yaf_View_Simple::render("menu.phtml"); ?>
	<div class="container">
	  <div class="content">
		<form role="form" class="form-horizontal" id="beform" action="update" method="post" enctype="multipart/form-data" >
          <input type="hidden" name="id" value="<?php echo $article['id']; ?>" />
		  <fieldset>
			<div class="form-group">
			  <!-- Select Basic -->
			  <label class="control-label col-lg-2">Category:</label>
			  <div class="controls col-lg-4">
				<select class="form-control" name="category">
                  <?php $select = null; ?>
				  <?php foreach($category as $value) { ?>
                  if($value['id'] == $article['category']){
                  $select = 'selected';
                  } ?>                  
				  <option value="<?php echo $value['id']; ?>" <?php echo $select; ?>><?php echo $value['name']; ?></option>
				  <?php } ?>
				</select>
			  </div>
			</div>
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="title">Title:</label>
			  <div class="col-lg-6">
				<input type="text" name="title" class="form-control" id="title" value="<?php echo $article['title']; ?>"/>
			  </div>
			</div>
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="">Author:</label>
			  <div class="col-lg-4">
				<input type="text" name="author" class="form-control" id="author"  value="<?php echo $article['author']; ?>"/>
			  </div>
			</div>
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="description">Description:</label>
			  <div class="col-lg-6">
				<textarea name="description" class="form-control" id="description" rows="5"><?php echo $article['description']; ?></textarea>
			  </div>
			</div>
			<div class="form-group">
			  <label class="col-lg-2 control-label">Contents:</label>
			  <div class="col-lg-10">
				<!-- <textarea name="contents" class="form-control" id="contents" rows="5"></textarea> -->
                <textarea name="contents" id="contents"><?php echo $article['contents']; ?></textarea>
                <!-- <textarea id="contents" name="contents"></textarea> -->
			  </div>
			</div>						
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="tag">Tag:</label>
			  <div class="col-lg-6">
				<input type="text" name="tag" class="form-control" id="tag" value="<?php echo $article['tag']; ?>"/>
			  </div>
			</div>						
			<div class="form-group">
			  <label class="col-lg-2 control-label" for="tag">Tag:</label>
			  <div class="col-lg-6">
				<input type="submit" class="form-control" />
			  </div>
			</div>
			<div class="form-group">
		      <label class="col-lg-2 control-label"></label>
		      <div class="col-lg-6">
		        <a  href="javascript:def.submit('#beform',null)" class="btn btn-primary">Submit</a>
		      </div>
            </div>
		  </fieldset>
		</form>
	  </div>
	</div>
	
	<!-- 模态框（Modal） -->
	<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="modellabel" aria-hidden="true">
	  <div class="modal-dialog">
		<div class="modal-content">
		  <div class="modal-header bg-default">
			<div class="modal-title" id="modallabel">
			  <h5 class="text-primary">Signal</h5>
			</div>
		  </div>
		  <div class="modal-body bg-primary">
			
		  </div>
		  <div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">Close
			</button>
		  </div>
		</div><!-- /.modal-content -->
	  </div><!-- /.modal -->
	</div>		

	<?php echo Yaf_View_Simple::render("footer.phtml"); ?>
    <script src="/asset/admin/js/summernote.js"></script>
	<script type="text/javascript">
     $(document).ready(function() {
         $('#contents').summernote({
             height: 300,             
             minHeight: null,         
             maxHeight: null,         
             focus: true,
             shortcuts: false,
             callbacks: {
                 onImageUpload: function(files) {
                     for(var i=0; i < files.length; i++) {
                         sendCMSFile(files[i]);
                     } 
                 }
             }
         });
     });
     function sendCMSFile(file) {
         if (file.type.includes('image')) {
             var name = file.name.split(".");
             name = name[0];
             var data = new FormData();
             data.append('file', file);
             $.ajax({
                 url: '/admin/image/upload',
                 type: 'post',
                 contentType: false,
                 cache: false,
                 processData: false,
                 dataType: 'json',
                 data: data,
                 success: function (data) {
                     var file = data.file;
                     var src = '/'+file.root_path+'/'+file.save_path+'/'+file.save_name;
                     $('#contents').summernote('insertImage',src);

                 },
                 error: function (jqXHR, textStatus, errorThrown) {
                     console.error(textStatus + " " + errorThrown);
                 }
             });
         }
     }

	</script>
  </body>
</html>
